package test;

import java.util.Arrays;
import java.util.Enumeration;
import java.util.Scanner;

/**
 * @author 郝文雪
 * @date 2022/9/19 19:44
 * @Description Test
 */
public class cvte1 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        int res=find(arr);
        System.out.println(res);
    }

    private static int find(int[] arr) {
        int res=Integer.MIN_VALUE;
        for(int i=0;i<arr.length;i++){
            if(arr[i]<=0) continue;
            int temp=0;
            for(int j=i;j< arr.length;j++){
                temp+=arr[j];
                if(res<temp){
                    res=temp;
                }
            }
        }
        Arrays.sort(arr);
        return Math.max(arr[arr.length-1],res);
    }
}
